package com.heo.music.player.controller;

import com.heo.music.player.auth.NeedLogin;
import com.heo.music.player.dto.input.PlaylistInput;
import com.heo.music.player.dto.output.MusicInfoOutput;
import com.heo.music.player.dto.output.PlaylistOutput;
import com.heo.music.player.service.PlaylistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * created on 2024-05-12 14:29
 *
 * @author 星天无极
 **/
@Api(tags = "播放列表管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class PlaylistController {

    private final PlaylistService playlistService;

    @ApiOperation("新增播放列表")
    @NeedLogin
    @PostMapping("/playlist")
    public PlaylistOutput createPlaylist(@Valid @RequestBody PlaylistInput input) {
        return playlistService.createPlaylist(input);
    }

    @ApiOperation("获取播放列表")
    @NeedLogin
    @GetMapping("/playlist")
    public List<PlaylistOutput> getAllPlaylist() {
        return playlistService.getAllPlaylist();
    }

    @ApiOperation("获取播放列表中音乐列表")
    @NeedLogin
    @GetMapping("/playlist/{playlistId}")
    public List<MusicInfoOutput> getMusicInfoInPlaylist(@PathVariable Integer playlistId) {
        return playlistService.getMusicInfoInPlaylist(playlistId);
    }

    @ApiOperation("播放列表中音乐列表")
    @NeedLogin
    @PostMapping("/playlist/{playlistId}/musicInfo/{musicId}")
    public void addMusicInfoToPlaylist(@PathVariable Integer playlistId, @PathVariable Integer musicId) {
        playlistService.addMusicInfoToPlaylist(playlistId, musicId);
    }

    @ApiOperation("删除播放列表中音乐")
    @NeedLogin
    @DeleteMapping("/playlist/{playlistId}/musicInfo/{musicId}")
    public void removeMusicInfoFromPlaylist(@PathVariable Integer playlistId, @PathVariable Integer musicId) {
        playlistService.removeMusicInfoFromPlaylist(playlistId, musicId);
    }

    @ApiOperation("删除播放列表")
    @NeedLogin
    @DeleteMapping("/playlist/{playlistId}")
    public void deletePlaylist(@PathVariable Integer playlistId) {
        playlistService.deletePlaylist(playlistId);
    }

}
